<?php

function send_voucher($ecv_type_id,$user_id=0,$is_password=false)
{
$ecv_type = $GLOBALS['db']->getRow('select * from '.DB_PREFIX.'ecv_type where id = '.$ecv_type_id);
if(!$ecv_type)return false;
if($is_password)$ecv_data['password'] = rand(10000000,99999999);
$ecv_data['use_limit'] = $ecv_type['use_limit'];
$ecv_data['begin_time'] = $ecv_type['begin_time'];
$ecv_data['end_time'] = $ecv_type['end_time'];
$ecv_data['money'] = $ecv_type['money'];
$ecv_data['ecv_type_id'] = $ecv_type_id;
$ecv_data['user_id'] = $user_id;
do{
$ecv_data['sn'] = uniqid();
$GLOBALS['db']->autoExecute(DB_PREFIX.'ecv',$ecv_data,'INSERT','','SILENT');
$insert_id = $GLOBALS['db']->insert_id();
}while(intval($insert_id) == 0);
if($insert_id)
{
$GLOBALS['db']->query('update '.DB_PREFIX.'ecv_type set gen_count = gen_count + 1 where id = '.$ecv_type_id);
}
return $insert_id;
}

?>